package com.boss.common.base;

import com.boss.sys.ca.user.dto.UserDTO;
import com.boss.sys.config.CseCommonConfiguration;
import com.boss.sys.utils.JsonUtil;
import com.boss.sys.utils.SysUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * <br>Title: 通用Controller类
 * <br>Description:通用Controller类
 * <br>Author: 朱孝恒
 * <br>Date: 2019年12月06日 16:27
 */
public class BasicinfoBaseController {
    /**
     * 错误码
     */
    public final static String ERROR_RSCODE = "140999";

    /**
     * 引入接口服务配置类
     */
    @Autowired
    private CseCommonConfiguration urlConfiguration;
    /**
     * 引入RestTemplate
     */
    @Autowired
    private RestTemplate restTemplate;


    public UserDTO getUser(String tokenid) throws Exception {
        try {
            Object userJsonStr = restTemplate.getForObject(urlConfiguration.getSso()+"/v1/user/token/{tokenid}", String.class, tokenid);
            Map<String, Object> userMap = JsonUtil.jsonToHashMap(SysUtils.nonNullStr(userJsonStr));
            UserDTO user = new UserDTO();
            user.putAll(userMap);
            if (user == null) {
                throw new Exception("用户不存在");
            }
            return user;
        } catch (Exception e) {
//            throw new Exception("查询用户信息失败！");
            UserDTO user = new UserDTO();
            user.setProvince("619900000");
            user.setYear(2020);
            return user;
        }
    }
}
